package com.rds.benchmark.connector;

import org.redisson.api.RedissonClient;
import redis.clients.jedis.Jedis;

public interface JedisConnector {

    int TIME_OUT = 60 * 1000 * 5; //60秒（单位milliseconds)

    int MAX_ATTEMPTS = 5;

    Object getJedis();

    /**
     * 验证是否连接正常
     *
     * @return 连接正常返回 true, 否则返回false
     */
    boolean test();

    String type();

    default void close(Object o) {
        if (o instanceof Jedis) {
            try {
                Jedis jedis = (Jedis) o;
                jedis.close();
            }catch (Throwable e) {}
        }
        if(o instanceof RedissonClient){
            ((RedissonClient) o).shutdown();
        }
    }
}
